﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DownloadApi.Net;

namespace FileDownloader
{
    public partial class dltest : Form
    {
        private DownloadClient dlClient = new DownloadClient();

        public dltest()
        {
            InitializeComponent();
         
            dlClient.ProgressChanged +=new EventHandler<DownloadClient.ProgressChangedEventArgs>(dlClient_ProgressChanged);
            dlClient.Cancelled += new EventHandler(dlClient_Cancelled);
            dlClient.Complete += new EventHandler(dlClient_Complete);

            // bgFileDownloader = dlClient.CreateWorker();


        }

        private void dltest_Load(object sender, EventArgs e)
        {

        
        }


        // This event handler updates the progress bar.
        private void dlClient_ProgressChanged(object sender,
            DownloadClient.ProgressChangedEventArgs e)
        {
            this.prgDownload.Value = e.Progress;

            Int64 kbRead = e.BytesRead / 1024;
            Int64 kbTotal = e.TotalBytes / 1024;
            this.lblProgress.Text = e.Progress + "% Downloaded " + kbRead + " KB of " + kbTotal + " KB";
        }

        private void dlClient_Cancelled(object sender, EventArgs e)
        {
            this.lblProgress.Text = "cancel";

        }

        private void dlClient_Complete(object sender, EventArgs e)
        {
            this.lblProgress.Text = "complete";

        }


        private void btnDownload_Click(object sender, EventArgs e)
        {
            // bgFileDownloader.RunWorkerAsync();
            dlClient.Start(txtUrl.Text, txtPath.Text, 0);
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            dlClient.Cancel();
        }
    }
}
